package com.cruise.common.redis.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * 类名：RedisConfig
 * 描述：TODO
 * @author cruise
 * 日期：2021/3/31 下午11:49
 * 版本：1.0
 **/
@Configuration
public class RedisConfig {


    @Autowired
    private StringRedisTemplate redisTemplate;

    @Bean
    public RedisTemplate redisTemplateInit() {

        //设置序列化Key的实例化对象
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        //设置序列化Value的实例化对象
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        return redisTemplate;

    }
}
